const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const tadayDate = function(str) {
  const date = new Date()
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  return [year, month, day].join('-')
}

const dateFormatAddOne = function(str) {

  var timestamp = Date.parse(new Date())
  timestamp = timestamp / 1000;
  //加一天的时间戳：  
  var tomorrow_timetamp = timestamp + 24 * 60 * 60;
  //加一天的时间：  
  var n_to = tomorrow_timetamp * 1000;  
  var tomorrow_date = new Date(n_to);  
  //加一天后的年份  
  var Y_tomorrow = tomorrow_date.getFullYear();  
  //加一天后的月份  
  var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1);  
  //加一天后的日期  
  var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate();  
  
  return [Y_tomorrow, M_tomorrow, D_tomorrow].join('-')
}

const addDateFormat = function(str){

  var timestamp = Date.parse(new Date())
  timestamp = timestamp / 1000;
  //加一天的时间戳：  
  var tomorrow_timetamp = timestamp + 168 * 60 * 60;
  //加一天的时间：  
  var n_to = tomorrow_timetamp * 1000;  
  var tomorrow_date = new Date(n_to);  
  //加一天后的年份  
  var Y_tomorrow = tomorrow_date.getFullYear();  
  //加一天后的月份  
  var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1);  
  //加一天后的日期  
  var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate();  
  
  return [Y_tomorrow, M_tomorrow, D_tomorrow].join('-')

}

module.exports = {
  formatTime: formatTime,
  tadayDate: tadayDate,
  dateFormatAddOne: dateFormatAddOne,
  addDateFormat: addDateFormat
}
